package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.Abstract;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.standard.StandardNames;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.wff.WffOp.applyMode;

@SuppressWarnings("serial")
public class WffKeyword implements WffCond
{
  private final WffBuildOp trm;

  public WffKeyword(WffBuildOp trm)
  {
    this.trm = trm;
  }

  @Override
  public applyMode satisfied(IAbstract env[], Location loc, WffEngine engine)
  {
    IAbstract term = trm.build(env, loc, engine);

    if (Abstract.isIdentifier(term) && StandardNames.isKeyword(Abstract.getId(term)))
      return applyMode.validates;
    else
      return applyMode.notValidates;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    trm.prettyPrint(disp);
    disp.append(StandardNames.WFF_DEFINES);
    disp.append(StandardNames.WFF_KEYWORD);
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }

}
